﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;

namespace YLPublicService.TransferModel
{
    /// <summary>
    /// 描述用户状态
    /// </summary>
    public enum UserState
    {
        Normal,
        Offline,//正常下线
        Kicked, //被强制下线
        Lost //其他问题导致连接中断
    }

    [DataContract]
    public class User
    {
        private Guid guid;
        /// <summary>
        /// 服务端利用Guid 保证公开的服务只有登录过的用户才能访问
        /// 生成Guid需要时间，所以只有在用户第一次登录才生成
        /// </summary>
        [DataMember]
        public Guid Guid
        {
            get { return guid; }
            set { guid = value; }
        }

        private string loginName;
        [DataMember]
        public string LoginName
        {
            get
            {
                CodeContract.RequiresArgumentNotNull(loginName, "LoginName");
                return loginName;
            }
            private set { loginName = value; }
        }

        private string passWord;
        [DataMember]
        public string PassWord
        {
            get
            {
                CodeContract.RequiresArgumentNotNull(passWord, "PassWord");
                return passWord;
            }
            private set { passWord = value; }
        }
        [DataMember]
        public bool Enabled { get; set; }

        public static User Create(string loginName, string pwd, bool enabled)
        {
            User u = new User();
            u.LoginName = loginName;
            u.PassWord = pwd;
            u.guid = Guid.NewGuid();
            u.Enabled = enabled;
            return u;
        }
        /// <summary>
        /// create empty user
        /// </summary>
        /// <param name="loginName"></param>
        /// <param name="enabled"></param>
        /// <returns></returns>
        public static User Create(string loginName, bool enabled)
        {
            User u = new User();
            u.LoginName = loginName;
            u.PassWord = "";
            u.guid = Guid.Empty;
            u.Enabled = enabled;
            return u;
        }
    }
}